package com.heima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.heima.mapper.PartnerMapper;
import com.heima.pojo.partner.Partner;
import com.heima.pojo.partner.PartnerPageResult;
import com.heima.pojo.partner.PartnerQueryParam;
import com.heima.pojo.sku.Sku;
import com.heima.service.PartnerService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
@RequiredArgsConstructor
public class PartnerServiceImpl implements PartnerService {
    private final PartnerMapper partnerMapper;
    /**
     *新增合作商
     * @param partner
     */
    @Override
    public void addPartner(Partner partner) {
        log.info("新增合作商：{}", partner);
        partner.setStatus(Partner.STATUS_DISABLE);
        /*partner.setCreateTime(LocalDateTime.now());
        partner.setUpdateTime(LocalDateTime.now());*/
        partnerMapper.addPartner(partner);
    }

    /**
     * 合作商搜索
     * @param param
     * @return
     */
    @Override
    public PartnerPageResult search(PartnerQueryParam param) {
        PageHelper.startPage(param.getPageIndex(),param.getPageSize());
        Page<Partner> page=partnerMapper.search(param);
        return new PartnerPageResult(page.getTotal(),page.getResult());
    }

    /**
     * 获取合作商详情
     * @param id
     * @return
     */
    @Override
    public Partner getById(Integer id) {
        log.info("获取合作商详情：{}", id);
       return partnerMapper.getById(id);
    }

    /**
     * 修改合作商
     * @param partner
     */
    @Override
    public void updatePartner(Partner partner) {
        /*partner.setUpdateTime(LocalDateTime.now());*/
        log.info("修改合作商：{}", partner);
        partnerMapper.updatePartner(partner);
    }

    /**
     * 删除合作商
     * @param id
     */
    @Override
    public void deletePartner(Integer id) {
        log.info("删除合作商：{}", id);
        partnerMapper.deletePartner(id);
    }
}
